using System;
using System.Collections.Generic;
using System.Reflection;
using System.Threading;
namespace Rogan.Data
{
	[Serializable]
	public class Entity
	{
		private readonly string _entityEame;
		private string _aliasName;
		private readonly List<Field> _changedFields = new List<Field>();
		private bool _isAttached;

		public Entity()
		{
		}
		public Entity(string entityEame) : this(entityEame, null)
		{
		}
		public Entity(string entityEame, string aliasName)
		{
			_entityEame = entityEame;
			_aliasName = aliasName;
		}
		public void Attach()
		{
			_isAttached = true;
		}
		public void DeAttach()
		{
			_isAttached = false;
		}
		public void OnPropertyValueChange(Field field, object oldValue, object newValue)
		{
			if (oldValue != newValue && _isAttached)
			{
				List<Field> obj;
				Monitor.Enter(obj = _changedFields);
				try
				{
					if (!_changedFields.Contains(field))
					{
						_changedFields.Add(field);
					}
				}
				finally
				{
					Monitor.Exit(obj);
				}
			}
		}
		public void ClearModifyFields()
		{
			_changedFields.Clear();
		}
		public List<Field> GetChangedFields()
		{
			return _changedFields;
		}
		public virtual object GetValue(string propertyName)
		{
			PropertyInfo property = GetType().GetProperty(propertyName);
			if (property != null)
			{
				return property.GetValue(this, null);
			}
			return null;
		}
		public virtual void SetValue(string propertyName, object value)
		{
			PropertyInfo property = GetType().GetProperty(propertyName);
			if (property != null)
			{
				property.SetValue(this, value, null);
			}
		}
		public virtual Field[] GetFields()
		{
			return null;
		}
		public virtual object[] GetValues()
		{
			return null;
		}
		public virtual Field[] GetPrimaryKeyFields()
		{
			return null;
		}
		public virtual Field GetIdentityField()
		{
			return null;
		}
		public virtual bool IsReadOnly()
		{
			return false;
		}
		public string GetName()
		{
			return _entityEame;
		}
		public string GetAliasName()
		{
			return _aliasName;
		}
		public void SetAliasName(string aliasName)
		{
			_aliasName = aliasName;
		}
	}
}
